package easycloud.ecs.common.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.BatchSize;
import org.springframework.data.jpa.domain.AbstractPersistable;

@SuppressWarnings("serial")
@MappedSuperclass
public abstract class AbstractItem extends AbstractPersistable<Integer> {

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "createProviderid")
	private Provider createProvider;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "updateProviderid")
	private Provider updateProvider;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "folderid")
	private Folder folder;

	@NotNull
	@Column(name = "path", nullable = false, length = 200)
	private String path;

	@NotNull
	@Column(name = "length", nullable = false)
	private long length;

	@Column(name = "lastModified", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastModified;

	@NotNull
	@Column(name = "createTick", nullable = false)
	private Integer createTick;

	@NotNull
	@Column(name = "updateTick", nullable = false)
	private Integer updateTick;

	@Column(name = "isDelete")
	private Boolean isDelete = false;

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, mappedBy = "item")
	@BatchSize(size = 10)
	private Set<Hash> hashs = new HashSet<Hash>();

	public Provider getCreateProvider() {
		return createProvider;
	}

	public Integer getCreateTick() {
		return createTick;
	}

	public Folder getFolder() {
		return folder;
	}

	public Set<Hash> getHashs() {
		return hashs;
	}

	public Boolean getIsDelete() {
		return isDelete;
	}

	public Date getLastModified() {
		return lastModified;
	}

	public long getLength() {
		return length;
	}

	public String getPath() {
		return path;
	}

	public Provider getUpdateProvider() {
		return updateProvider;
	}

	public Integer getUpdateTick() {
		return updateTick;
	}

	public void setCreateProvider(Provider createProvider) {
		this.createProvider = createProvider;
	}

	public void setCreateTick(Integer createTick) {
		this.createTick = createTick;
	}

	public void setFolder(Folder folder) {
		this.folder = folder;
	}

	public void setHashs(Set<Hash> hashs) {
		this.hashs = hashs;
	}

	public void setIsDelete(Boolean isDelete) {
		this.isDelete = isDelete;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	public void setLength(long length) {
		this.length = length;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public void setUpdateProvider(Provider updateProvider) {
		this.updateProvider = updateProvider;
	}

	public void setUpdateTick(Integer updateTick) {
		this.updateTick = updateTick;
	}
}
